package com.User.Controller;

import com.User.entity.User;
import com.User.service.UserService;
import com.utils.APIRespones;
import com.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/users")
public class UserController {
    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/isLogin")
    public APIRespones isLogin(@RequestBody String token) {
        return userService.isLogin(token);
    }


    @PostMapping("/login")
    public APIRespones login(@RequestBody User user) {
        System.out.println("登录功能启动");
        return userService.login(user.getUsername(), user.getPassword());
    }

    @PostMapping("/register")
    public APIRespones register(@RequestBody User user) {
        System.out.println(user);
        System.out.println("注册功能启动");
        return userService.register(user);
    }
    @GetMapping("/userInfo")
    public APIRespones getUserInfo(@RequestParam String token){
        System.out.println("查询用户信息");
        return userService.getUserInfo(token);
    }
    @PostMapping("/head")
    public APIRespones uploadUserHead(@RequestParam("file") MultipartFile file, @RequestParam("token") String token) {
        return userService.uploadUserHead(file,token);
    }


}
